package cn.edu.scau.cmi.zhangjunjia.singleton;

import java.util.HashSet;
import java.util.Set;

public class Marshal {
	
	private String name;
	private static Set<Marshal> marshalSet = new HashSet<>();
	private static Set<String> nameList = new HashSet<>();
	private static Marshal marshal;
	
	private Marshal(String name) {
		this.name = name;
	}
	
	public static Marshal getInstance(String name) {
		if(marshalSet.size()<10) {
			marshal = new Marshal(name);
			marshalSet.add(marshal);
		}
		return marshal;
	}
	
	public static String judgeName(String name) {
		if(marshalSet.size()<10) {
			if(nameList.contains(name)) {
				return (name+" maeshal has been created!\n");
			}
			else {
				nameList.add(name);
			}		
		}
		else {
			return("You have been created over ten maeshal!!!");
		}
		return "1";
	}
	
	public void setName(String name) {
		this.name=name;
	}

}
